/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tallerfinal.view.distributions.factory;

import java.lang.reflect.InvocationTargetException;
import java.util.TreeMap;
import tallerfinal.util.enums.DistributionsName;
import tallerfinal.view.distributions.GeneratorView;

/**
 *
 * @author ricardo
 */
public class GeneratorViewFactory {

    private static GeneratorViewFactory instance;

    private GeneratorViewFactory() {
    }
    private TreeMap<DistributionsName, Class> m_RegisteredProducts = new TreeMap<>();

    public void registerProduct(DistributionsName productID, Class productClass) {
        m_RegisteredProducts.put(productID, productClass);
    }

    public synchronized static GeneratorViewFactory getInstance() {
        if (instance == null) {
            instance = new GeneratorViewFactory();
        }
        return instance;
    }

    public GeneratorView createGenerator(DistributionsName generatorId) throws NoSuchMethodException, InstantiationException, InvocationTargetException, IllegalAccessException {
        Class<?> generatorClass = m_RegisteredProducts.get(generatorId);
        return (GeneratorView) generatorClass.newInstance();

    }
}
